let nav = document.querySelector("#nav")
let brond = document.querySelector("#Brand")
let Rank = document.querySelector("#Rank")

function navlist() {
    let res;
    ajax({
        url: "http://chst.vip:1234/api/getcategorybyid",
        success(res) {
            res = res.result;
            let html = "";
            html = `<a href="../pages/index.html">首页></a>
                <a href="../pages/brandTitle.html">全部分类></a>
                <a href="#">筛选</a>`
            nav.innerHTML = html
        },
        error(err, xhr) {
            console.log(err);
        }
    })
}
navlist()
let res;
let res1
ajax({
    url: "http://chst.vip:1234/api/getbrandtitle",
    success(res) {
        res = res.result;
        let html = "";
        let currentArr = res.splice(0, 10);
        currentArr.forEach(itme => {
            html += `
                <div class="Brand">
                <p class="p" >${itme.brandTitle}</p>
                </div>
                <ul class="uu">
                </ul>
            `
        })
        brond.innerHTML = html
        let p = [...document.querySelectorAll(".p")];
        let ul = [...document.querySelectorAll(".uu")];
        p.forEach(function(item, index) {
            let j = 0
            item.onclick = function() {
                j++
                if (j % 2 === 0) {
                    ul[index].style.height = 0 + "rem"

                } else {
                    ul[index].style.height = 20 + "rem"
                    ajax({
                        url: "http://chst.vip:1234/api/getbrand",
                        success(res) {
                            console.log(res);
                            res1 = res.result;
                            let html1 = "";
                            let currentArr = res1.splice(0, 10);
                            currentArr.forEach(itme => {
                                console.log(itme);
                                html1 += `
                             <li>${itme.productImg}</li>
                                            `
                            });
                            ul.forEach(function(itme, index) {
                                itme.innerHTML = html;
                            })
                        },
                        data: {
                            brandtitleid: 0,
                            pagesize: 0
                        },

                        error(err, xhr) {
                            console.log(err);
                        }

                    })
                }
            }

        })
    },
    error(err, xhr) {
        console.log(err);
    }
})